/**
 *
 */
package com.naiterui.ehp.bs.doctor.repository;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bp.domain.DrPatientGroupDetail;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * 医生患者分组详情
 * @author guoyongxiang
 * @since 2.7.0
 */
@Repository
public interface IDrPatientGroupDetailRepository extends BaseJpaRepository<DrPatientGroupDetail, Long> {

    List<DrPatientGroupDetail> findByGroupIdAndDoctorId(Long groupId, Long doctorId);

    List<DrPatientGroupDetail> findByGroupIdInAndDoctorId(List<Long> groupIds, Long doctorId);

    List<DrPatientGroupDetail> findByDoctorId(Long doctorId);

    List<DrPatientGroupDetail> findByDoctorIdAndPatientIdIn(Long doctorId, List<Long> patientIds);

    List<DrPatientGroupDetail> findByDoctorIdAndPatientId(Long doctorId, Long patientId);

    void deleteByGroupId(Long groupId);

    void deleteByGroupIdAndPatientIdIn(Long groupId, List<Long> patientIds);

    void deleteByGroupIdInAndPatientId(Set<Long> groupIds, Long patientId);

    @Query(value = "SELECT group_id, count(patient_id) from dr_patient_group_detail where doctor_id=?1 group by group_id", nativeQuery = true)
    List<Object> getPatientCountInGroup(Long doctorId) ;

    List<DrPatientGroupDetail> findByGroupIdIn(List<Long> groupIds);

    void deleteByDoctorIdAndPatientId(Long doctorId, Long patientId);

}
